<?php
/**
 * TestGuest Version1.0
 * ================================================
 * Copy 2017-2018 zxj
 * Web: http://www.zhaoxiaojie.club
 * ================================================
 * Author: Zxj
 * Date: 17/8/10
 * Time: 上午10:11
 */
//1.设置响应头
header('content-type:text/html;charset=utf-8');

//2.引入函数库
include_once 'common/function.inc.php';

//处理表单提交请求
$act = isset($_REQUEST['act'])?$_REQUEST['act']:'';
if($act=='add'){
//接受并验证数据

$title = _guo_lv($_POST['title']);
$description = _guo_lv($_POST['description']);
$pid = _guo_lv($_POST['pid']);
$sort = _guo_lv($_POST['sort']);
$time = date('Y-m-d H:i:s');  //获取当前时间
//echo $addtime;die();
//    echo '<pre/>';
//    print_r($_REQUEST);
//    print_r($_GET);
//   var_dump($_POST);die();
//连接数据库
    include_once 'common/mysql.inc.php';
    $sql = "insert into bbs_forum VALUES (null,'$title','$description','$pid','$sort','$time')";

    $res = mysql_query($sql);
    //var_dump($res);die();
    if($res && mysql_affected_rows()>0){

        echo '<script>alert("添加成功!");window.location.href="forum_list.php";</script>';
        //释放资源
        mysql_free_result($res);
        //关闭连接
        mysql_close($link);

        exit();

    }else{

        _alert_back('添加失败!');

    }

}elseif($act=='edit'){

    $id = _guo_lv($_POST['id']);
    $title = _guo_lv($_POST['title']);
    $description = _guo_lv($_POST['description']);
    $pid = _guo_lv($_POST['pid']);
    $sort = _guo_lv($_POST['sort']);
    $time = date('Y-m-d H:i:s');  //获取当前时间
//echo $addtime;die();
//连接数据库
    include_once 'common/mysql.inc.php';
    $sql = "update bbs_forum set title='$title',description='$description',pid='$pid',sort='$sort',addtime='$time' WHERE id=$id";
    $res = mysql_query($sql);
    if($res && mysql_affected_rows()>0){

        echo '<script>alert("修改成功!");window.location.href="forum_list.php";</script>';
        //释放资源
        mysql_free_result($res);
        //关闭连接
        mysql_close($link);

        exit();

    }else{

        _alert_back('修改失败!');

    }



}elseif($act=='del'){

    //var_dump($_POST);

    $ids = $_POST['id'];
    //连接数据库
    include_once 'common/mysql.inc.php';
    $sql = "delete from bbs_forum WHERE id in ($ids)";
    $res = mysql_query($sql);
    if($res && mysql_affected_rows()>0){

        $ajaxData['status'] = 1;
        $ajaxData['msg'] = '批量删除成功！';
        echo json_encode($ajaxData);     //必须要echo 不然客户端接收不到数据

    }else{

        $ajaxData['status'] = 0;
        $ajaxData['msg'] = '批量删除失败！';
        echo json_encode($ajaxData);     //必须要echo 不然客户端接收不到数据
    }


}else{

    echo '<script>alert("数据异常!");window.parent.location.href="forum_list.php";</script>';

}



?>